# -*- coding: utf-8 -*-
from jms.aigroup.ai_dwd.yl_ml_clean_address_day_tmp import jms_ai_dwd__yl_ml_clean_address_day_tmp
from jms.aigroup.ai_group.geo_info_day import jms_aigroup__geo_info_day
from utils.operators.latest_only_spark_submit_operator import LatestOnlySparkSubmitOperator
from jms.aigroup.ai_dwd.yl_ml_clean_address_new_day_tmp import jms_ai_dwd__yl_ml_clean_address_new_day_tmp

# def kwargs():
#     kwargs = {
#         "db": "ai_group",
#         "table": "train_sample",
#         "desc": "模型训练经纬度地址数据",
#         "taskid": "10060",
#         "ifprivacy": 0,
#         "warnignore": 0,
#     }
#     return kwargs

jms_ai_dwd__train_sample_tmp = LatestOnlySparkSubmitOperator(
    task_id='jms_ai_dwd__train_sample_tmp',
    conn_id='spark_default',
    pool_slots=15,
    # depends_on_past=True,  # 如果任务依赖于前一天的同名任务，则将 depends_on_past 设为 True
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    name='jms_ai_dwd__train_sample_tmp_{{ execution_date| date_add(1) | cst_ds }}',  # yarn 任务名称
    driver_memory='10G',
    executor_memory='8G',
    executor_cores=4,
    num_executors=20,
    depends_on_past=False,
    email=['yushuo@jtexpress.com','yl_bigdata@yl-scm.com'],
    conf={'spark.core.connection.ack.wait.timeout': 300,
          'spark.locality.wait': 60,
          'spark.dynamicAllocation.maxExecutors': 60,
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 40,
          'spark.dynamicAllocation.enabled': 'true',
          'spark.shuffle.service.enabled': 'true',  # NodeManager中一个长期运行的辅助服务，用于提升Shuffle计算性能
          'spark.executor.memoryOverhead': '1G',
          'spark.default.paralleism': '720',  # spark.default.parallelism只有在处理RDD时有效.
          'spark.sql.shuffle.partitions': 720,  # spark.sql.shuffle.partitions则是只对SparkSQL有效
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 100000,  #
              'hive.exec.max.dynamic.partitions.pernode': 1000,  #
              },
    java_class='com.yunlu.bigdata.jobs.ml.TrainSampleForMLUD',  # spark 主类
    # application='hdfs:///user/spark/work/aigroup/train_sample/jobs-1.0-SNAPSHOT-jar-with-dependencies.jar',  # spark jar 包
    application='hdfs:///scheduler/jms/spark/lyx/ml/train_sample/jobs-1.0-SNAPSHOT-jar-with-dependencies.jar',
    # spark jar 包
    application_args=['{{ execution_date | cst_ds_nodash }}'],  # 参数dt 20201026
    # on_success_callback=yl_threeSegCodeOnSuccess(kwargs(), dingding_conn_id="dingding_ThreeSeg_etl_info"),
    # on_failure_callback=yl_threeSegCodeOnFailure(kwargs(), dingding_conn_id="dingding_ThreeSeg_etl_alert"),
)

# 设置依赖
jms_ai_dwd__train_sample_tmp << [
    # jms_ai_dwd__yl_ml_clean_address_day_tmp,
    jms_ai_dwd__yl_ml_clean_address_new_day_tmp,
    jms_aigroup__geo_info_day]
